import React, { Component } from 'react'
import {Route, Switch, Redirect} from "react-router-dom"   // 分别暴露
import Home from "./pages/Home"               // Home是路由组件
import About from "./pages/About"             // About是路由组件
import Header from './components/Header'      // Header是一般组件
import MyNavLink from './components/MyNavLink'

export default class App extends Component {
  render() {
    return (
      <div>
        <div className="row">
          <div className="col-xs-8 col-md-8 col-lg-8 offset-xs-2 offset-md-2 offset-lg-2">
            <Header/>
          </div>
        </div>
        <div className="row">
          <div className="col-xs-2 col-md-2 col-lg-2 offset-xs-2 offset-md-2 offset-lg-2">
            <div className="list-group">
              {/* 原生html中，靠<a>跳转不同的页面 */}
              {/* <a className="list-group-item" href=" . / about.html">About</a>
              <a className="list-group-item active" href=" . / home.html">Home</a> */}

              {/* 在React中靠路由链接实现切换组件--编写路由链接 */}
              {/* <BrowserRouter> */}
              {/* <MyNavLink url="/about" menu="About"/>
              <MyNavLink url="/home" menu="Home"/> */}
              
              <MyNavLink to="/about" children="About"/>
              <MyNavLink to="/home">Home</MyNavLink>
              {/* </BrowserRouter> */}
            </div>
          </div>
          <div className="col-xs-6 col-md-6 col-lg-6 col-xs-offset-2 col-md-offset-2 col-lg-offset-2">
            <div className="panel">
              <div className="panel-body">
                {/* 注册路由 */}
                {/* <BrowserRouter> */}
                {/* 路由去重，只展示第一个 */}
                <Switch>
                  <Route path="/about" component={About}></Route>
                  <Route exact path="/home" component={Home}></Route>
                  {/* 默认是精准匹配  这样才能高亮 */}
                  <Redirect to="/about" />
                </Switch>
                {/* </BrowserRouter> */}
              </div>
            </div>
          </div>
        </div>
      </div>
    )
  }
}
